<?php
include("../autoload.php");
$sessao = new Sessao();
$sessao->setSessionName("projeto");
$sessao->iniciaSessao();
$nivel = Util::retornaNivel($sessao->getVarSessao('codtipo'));
$logado = $sessao->getVarSessao('codigo_logado');

$tipo = $_GET['tipo'];
$assessor = $_GET['cmbassessor'];
if($tipo == "usuario"){
    $ajax_lista_busca = "ajax/busca_usuario.php";
}else{
    $ajax_lista_busca = "ajax/busca_clientes.php";
}
?>
<div onclick="alteraDisplayDiv('DivPesquisaCliente');" style="float:right;position:relative;width:80px;height: 20px;background-image:url(img/fechar.png);cursor:pointer;"></div>
<form name="frmBusca" id="frmBusca" method="post" action="" onsubmit="return false;">
    <table style="margin-left:10px;margin-top:30px;">
        <tr>
            <td width="245">
                <input name="txtNome" id="txtNome" type="text" placeholder="Nome" style="width:242px;height: 30px;font-size:24px;color:#666666;" />
            </td>
            <td width="25">
            <input type="submit" name="btBuscar" id="btBuscar2" value=" " onclick="ListaResultadosBusca('frmBusca', 'tdRetornoBusca', '<?php echo $ajax_lista_busca;?>');" />
            </td>
        </tr>
        <?php
        if($tipo == "usuario"){
        ?>
            <input type="hidden" name="cmbAssessor" id="cmbAssessor" value="<?php echo $assessor;?>" />
        <?php
        }else{
        ?>
            <tr>
                <td align="left" colspan="2">Assessor: 
                
                    <?php
                    $tipoAssessor = Util::retornaTipo("Assessor");
                    if($nivel <= 1){
                        $strWhere = " AND codigo = '$logado'";
                    }else if($nivel < 3){
                        $strWhere = " AND codsupervisor = '$logado'";
                    }else{
                        $strWhere = "";
                    }

                    $listaAssessores = Usuarios::Lista_usuario(" WHERE codtipo = '$tipoAssessor' $strWhere ORDER BY nome ");
                    ?>
                    <select name="cmbAssessor" id="cmbAssessor">
                        <?php
                        foreach($listaAssessores as $lista){
                        ?>
                            <option value="<?php echo $lista->getCodigo();?>" 
                                <?php 
                                    if ($assessor == $lista->getCodigo()) {
                                        echo "selected=\"selected\"";
                                    }
                                ?>><?php echo utf8_encode($lista->getNome());?></option>
                        <?php
                        }
                        ?>
                    </select>
                </td>
            </tr>
        <?php
        }
        ?>
        <tr>
            <td id="tdRetornoBusca" align="center" colspan="3">
                <select name="cmbLista" id="cmbLista" style="width: 290px;" size="15"></select>
            </td>
        </tr>
    </table>
</form>